/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package controller;

import GestureRecognition.Gestures;
import UserInterface.FinalGUI;
import camera.SkinBasedCamera;
import utilities.CoordinateFinder;
import utilities.FinalImageCanvas;

/**
 *
 * @author HOME
 */
public class SkinBasedController implements Runnable {

    final int CAM_NUM1, CAM_NUM2, CAM_FOV = 84;
    public boolean isConsecutive = false;
    CoordinateFinder coFind = new CoordinateFinder();
    FinalImageCanvas imcanv = new FinalImageCanvas();
     public static int[] ty;
    Gestures ges = new Gestures();
//    private int rel_case1;
//    private int rel_case2;
    // FinalGUI gui = new FinalGUI();

    public SkinBasedController(int CAM_NUM1, int CAM_NUM2) {
        this.CAM_NUM1 = CAM_NUM1;
        this.CAM_NUM2 = CAM_NUM2;
    }

    @Override
    public void run() {

        // Initialize Cameras
        SkinBasedCamera cam1 = new SkinBasedCamera(CAM_NUM1, CAM_FOV);
        Thread th = new Thread(cam1);
        th.start();

        SkinBasedCamera cam2 = new SkinBasedCamera(CAM_NUM2, CAM_FOV);
        Thread th1 = new Thread(cam2);
        th1.start();

        
        double theta, beeta, gamma, delta;

        try {
            Thread.sleep(7000);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
        while (true) {
            // System.out.println("Running");
            beeta = cam1.getTheta();
            theta = cam2.getTheta();
//            rel_case1 = cam1.rel_case;
//            rel_case2 = cam2.rel_case;
//            System.out.println("Cam1 beeta= " + beeta + " Cam2 theta= " + theta);

            delta = Math.toRadians(90) - beeta;
            gamma = Math.toRadians(90 - CAM_FOV) + theta;

            ty = coFind.getCoordinate(1, delta,gamma);
//            System.out.println("Final Coordinate= x=" + ty[0] + " y= " + ty[1]);

            // Still case 1 is assumed

//            if (rel_case1 == 2 && rel_case2 == 2) {
//                System.out.println("2 n 2");
//                theta1 = cam2.getTheta1();
//                beeta1 = cam1.getTheta1();
//                gamma1 = Math.toRadians(40) - theta1;
//                delta1 = Math.toRadians(40) - beeta1;
//                ty1 = coFind.getCoordinate(1, gamma1, beeta1, 800);
//                ges.identifyGestureType(ty, ty1, isConsecutive);
//                isConsecutive = true;
                FinalGUI.setX_Y(ty[0], ty[1]);
                //   imcanv.paint(ty[0], ty[1], "BLACK");

//            } else if (rel_case1 == 1 && rel_case2 == 1) {
//                System.out.println("1 n 1");
//                //   isConsecutive = false;
//                //   imcanv.paint(ty[0], ty[1], "BLACK");
//                FinalGUI.setX_Y(ty[0], ty[1]);
//
//            } else if ((rel_case1 == 1 && rel_case2 == 2) || (rel_case1 == 2 && rel_case2 == 1)) {
//                System.out.println("o o");
//                FinalGUI.setX_Y(ty[0], ty[1]);
//
//            } else {
//
//                //  isConsecutive = false;
//                // imcanv.paint(0, 0, "BLACK");
//                FinalGUI.setX_Y(0, 0);
//            }



        }
    }
}
